package view.mediator.monster.large_monster
{
	
	import flash.system.System;
	
	import model.monster.MonsterModel;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import view.component.monster.large_monster.LargeMonsterView;
	import view.event.monster.LargeMonsterViewEvent;
	
	
	/**
	 * largeMonsterView界面中介
	 * @author £iang
	 * 
	 */	
	public class LargeMonsterViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** LargeMonsterView界面 */
		[Inject]
		public var largeMonsterView:LargeMonsterView;
		/** monsterModel */
		[Inject]
		public var monsterModel:MonsterModel;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 *  注册函数
		 * 
		 */		
		override public function onRegister():void
		{
			addContextListener( LargeMonsterViewEvent.SCROLLER_PAGE, scrollerPageHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理滚动条翻页的消息 
		 * @param event 选中查看的怪物后派发的消息 
		 * 
		 */		
		protected function scrollerPageHandler( event:LargeMonsterViewEvent ):void
		{
			largeMonsterView.changePage( event.newPage );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeContextListener( LargeMonsterViewEvent.SCROLLER_PAGE, scrollerPageHandler );
			monsterModel.clearCurLMonsterData();
			largeMonsterView.mainContainer.removeChild( largeMonsterView.listView, true );
			largeMonsterView.listView = null;
			largeMonsterView.mainContainer.removeChild( largeMonsterView.detailView, true );
			largeMonsterView.detailView = null;
			System.gc();
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function LargeMonsterViewMediator()
		{
			super();
		}
	}
}